package 代码记录.Bit48天集训;

import java.util.Scanner;

/**编程题已搞定
 * 1.查找输入整数二进制中1的个数
 * 2.手套
 * @author zx
 * @create 2022-05-10 19:46
 */
public class day_15 {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()){
            int n = sc.nextInt();
            System.out.println(Sum1(n));
        }
    }
    private static int Sum1(int n){
        int res = 0;
        while(n != 0){
            n = n & (n - 1);
            res++;
        }
        return res;
    }

    /**
     * 对于左右手手套颜色都有数量的序列,想要覆盖每一种颜色,则最小数量
     * leftsum = 左边数量和 - 左边最小值 + 1, rightsum = 右边数量和 - 右边的最小值 + 1.
     * 特殊情况：对于有0存在的,则需要做累加,保证覆盖每一种颜色.
     */
    public int findMinimum(int n, int[] left, int[] right) {
        int sum = 0;
        int leftSum = 0, rightSum = 0;
        int leftMin = Integer.MAX_VALUE, rightMin = Integer.MAX_VALUE;
        for (int i = 0; i < n; i++) {
            if (left[i] * right[i] == 0) {
                sum += (left[i] + right[i]);
            } else {
                leftSum += left[i];
                rightSum += right[i];
                leftMin = Math.min(leftMin, left[i]);
                rightMin = Math.min(rightMin, right[i]);
            }
        }
        return sum + Math.min(leftSum - leftMin + 1, rightSum - rightMin + 1) + 1;
    }
}
